#ifndef HISTOGRAM_HISTOGRAM_H
#define HISTOGRAM_HISTOGRAM_H

#include <iostream>
#include <vector>

class Histogram
{
public:
    enum Type
    {
        DESTRIBUTION = 1,
        GRADIENT = 2,
        MULTI = DESTRIBUTION | GRADIENT
    };

    Histogram(int count = 256, Histogram::Type type = DESTRIBUTION):_type(type), _binCoint(count)
    {
        _bins = new unsigned int[_binCoint];
    }
    ~Histogram()
    {
        delete[] _bins;
    }
    Histogram& operator=(Histogram& other)
    {
        if( &other == this ) return *this;
        _type = other._type;
        _binCoint = other._binCoint;
        if(_bins) delete[] _bins;
        _bins = new unsigned int[_binCoint];
        for(int i = 0; i < _binCoint; ++i)
        {
            _bins[i] = other._bins[i];
        }
        return *this;
    }
    Histogram(Histogram& other)
    {
        _type = other._type;
        _binCoint = other._binCoint;
        _bins = new unsigned int[_binCoint];
        for(int i = 0; i < _binCoint; ++i)
        {
            _bins[i] = other._bins[i];
        }
    }
    unsigned int *bins() {return _bins;}
    friend std::ostream& operator<<(std::ostream& output, const Histogram& histogram);
    std::vector<int> classify(double peak_threshold);
private:
    Type _type;
    unsigned int *_bins;
    int _binCoint;

};
inline Histogram::Type operator|(Histogram::Type a, Histogram::Type b)
{
    return static_cast<Histogram::Type>(static_cast<int>(a) | static_cast<int>(b));
}

#endif
